<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="keHu">
              <a-input v-model="model.keHu" placeholder="请输入客户"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wuLiaoBianMa">
              <a-input v-model="model.wuLiaoBianMa" placeholder="请输入物料编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="品番" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pinFan">
              <a-input v-model="model.pinFan" placeholder="请输入品番"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="供应商代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gongYingShangCode">
              <a-input v-model="model.gongYingShangCode" placeholder="请输入供应商代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xingHao">
              <a-input v-model="model.xingHao" placeholder="请输入型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shengChanRiQi">
              <a-input v-model="model.shengChanRiQi" placeholder="请输入生产日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="班次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="banCi">
              <a-input v-model="model.banCi" placeholder="请输入班次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单箱数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="danXiangShuLiang">
              <a-input v-model="model.danXiangShuLiang" placeholder="请输入单箱数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zongShu">
              <a-input v-model="model.zongShu" placeholder="请输入总数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产批次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shengChanPiCi">
              <a-input v-model="model.shengChanPiCi" placeholder="请输入生产批次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="唯一序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sn">
              <a-input v-model="model.sn" placeholder="请输入唯一序列号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="箱号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xiangHao">
              <a-input v-model="model.xiangHao" placeholder="请输入箱号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="作业员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zuoYeYuan">
              <a-input v-model="model.zuoYeYuan" placeholder="请输入作业员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="检查员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jianChaYuan">
              <a-input v-model="model.jianChaYuan" placeholder="请输入检查员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="环保要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huanBaoYaoQiu">
              <a-input v-model="model.huanBaoYaoQiu" placeholder="请输入环保要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qrCode">
              <a-input v-model="model.qrCode" placeholder="请输入二维码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChSpotTicketTempForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chSpotTicketTemp/add",
          edit: "/ch/chSpotTicketTemp/edit",
          queryById: "/ch/chSpotTicketTemp/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>